/**
 * 查询所有未提现订单接口
 */

//引入Q模块
let Q = require('q');
//引入公共函数
let util = require('../../util');

let index = function(getData, postData, config, _redis, db) {
	let deferred = Q.defer();
	if(postData.year && postData.month) {
		let date = new Date();
		if(postData.year > date.getFullYear() || (postData.year > date.getFullYear() && postData.month > date.getMonth() - 1)) {
			deferred.resolve([]);
		}
		else {
			let startTimestamp = parseInt(new Date(postData.year + '/' + postData.month + '/1').getTime() / 1000);
			let endTimestamp = 0;
			endTimestamp = parseInt(new Date(postData.year + '/' + postData.month + '/' + (date.getMonth() + 1 == postData.month ? date.getDate() + 1 : (new Date(postData.year, postData.month, 0).getDate() ))).getTime() / 1000) - 259201;
			db.select('storeOrder', {
				userPayed: true,
				payMode: 'wxPay',
				timestamp: {
					$gte: startTimestamp,
					$lte: endTimestamp
				}
			}).then(function(orderData) {
				deferred.resolve(orderData);
			}, function() {
				//查询所有未提现订单失败
				deferred.reject('-0120');
			});
		}
	}
	else {
		//查询所有未提现订单接口参数不足
		deferred.reject('-0119');
	}
	return deferred.promise;
}

module.exports = {
	index: index
}